import java.net.*;
import java.util.Scanner;
import java.io.*;

public class GameUpdaterThread extends Thread {
    ChatPanel chat;
    private Socket socket;
    private GameQueue gamequeue;
    private int id;
    Scanner sc;
    
    public GameUpdaterThread(Scanner s, Socket socket, GameQueue gamequeue, ChatPanel panel, int id) {
    	sc = s;
        chat = panel;
        this.socket = socket;
        this.gamequeue = gamequeue;
        this.id = id;
    }
    
    public void run() {
        try {
                String username = sc.next(), msg = "";
                    while(sc.hasNext()) { msg += sc.nextLine(); }
                    sc.close();
                    
                    if(!msg.trim().equals("NONE"))
                    	gamequeue.add(id,username,msg);
                    else
                    	chat.receiveEndedGame(id,username);
            socket.close();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } 
    }
}